home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / movement / Switch Player.lua < prev    next >
Encoding:
Text File  |  2010-04-17  |  2.1 KB  |  62 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Switch Player
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, September 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.switchplayer={}
  10.  
  11. -- Load & Prepare Ressources
  12. cc.switchplayer.gfx_wpn=loadgfx("weapons/switchplayer.png")                                    -- Weapon Image
  13. setmidhandle(cc.switchplayer.gfx_wpn)
  14. cc.switchplayer.sfx_attack=loadsfx("boing.ogg")
  15.  
  16.  
  17. --------------------------------------------------------------------------------
  18. -- Weapon: Switch Player
  19. --------------------------------------------------------------------------------
  20.  
  21. cc.switchplayer.id=addweapon("cc.switchplayer","Switch Player",cc.switchplayer.gfx_wpn,0)    -- Add Weapon
  22.  
  23. function cc.switchplayer.draw()                                                                -- Draw
  24.     setblend(blend_alpha)
  25.     setalpha(1)
  26.     setcolor(255,255,255)
  27.     setscale(0.5+math.abs(math.sin(math.rad(weapon_charge)))*0.5,0.5+math.cos(math.sin(math.rad(weapon_charge)))*0.5)
  28.     drawimage(cc.switchplayer.gfx_wpn,getplayerx(0),getplayery(0)-30)
  29.     -- Animation
  30.     weapon_charge=weapon_charge+5
  31.     if weapon_charge>=360 then weapon_charge=0 end
  32.     -- HUD Positioning
  33.     hudpositioning(pos_invisible)
  34.     -- HUD Info
  35.     hudinfo("Click a player of your team to switch!")
  36. end
  37.  
  38. function cc.switchplayer.attack(attack)                                                        -- Attack
  39.     if (weapon_position==1) then
  40.         weapon_position=0
  41.         weapon_shots=weapon_shots+1
  42.         -- Find clicked player with collision
  43.         switchto=0
  44.         if collision(col3x3,weapon_x,weapon_y,0,1)==1 then
  45.             if playercollision()~=0 then
  46.                 if getplayerhealth(playercollision())>0 and getplayerteam(playercollision())==getplayerteam(0) then
  47.                     switchto=playercollision()
  48.                 end
  49.             end
  50.         end
  51.         -- Perform switching when player has been found
  52.         if switchto~=0 and switchto~=playercurrent() then
  53.             -- Use weapon and allow to use another one afterwards (1)
  54.             useweapon(1)
  55.             -- SFX
  56.             playsound(cc.switchplayer.sfx_attack)
  57.             -- Switch
  58.             playerswitch(switchto)
  59.             scroll(getplayerx(switchto),getplayery(switchto))
  60.         end
  61.     end
  62. end